package com;

import com.spring.helper.BeanHelper;
import com.spring.helper.ClassHelper;
import com.spring.helper.IocHelper;

public class LoadHelper {

    /**
     * 初始化，加载指定的类，目的是执行指定类的静态代码块，达到初始化bean容器的效果
     */
    public static void init() {
        Class<?>[] classes = new Class[]{ClassHelper.class, BeanHelper.class, IocHelper.class};

        for (Class<?> aClass : classes) {
            loadClass(aClass);
        }
    }

    /**
     * 加载类
     * @param cls
     */
    private static void loadClass(Class<?> cls) {
        try {
            Class.forName(cls.getName(), true, getClassLoader());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    /**
     * 获取类加载器
     * @return
     */
    public static ClassLoader getClassLoader() {
        return Thread.currentThread().getContextClassLoader();
    }

}
